//
//  GWAudiosView.swift
//  GhostWorld
//
//  Created by Kam on 2018/4/5.
//  Copyright © 2018 LKGood. All rights reserved.
//

import UIKit

class GWAudiosView: UIView {

  // MARK: - IBOutlets
  
  @IBOutlet private weak var stackView: UIStackView!
  
  // MARK: - Private vars
  
  
  
  // MARK: - Private methods
  
  
  
  // MARK: - Public vars
  
  
  
  // MARK: - Lifecycle
  
  
  
  // MARK: - IBActions
  
  
  
  // MARK: - Public methods
  
  func prepare(audios: [Audio]) {
    subviews.forEach {
      if type(of: $0) == GWAudioItem.self {
        $0.removeFromSuperview()
      }
    }
    for (index, audio) in audios.enumerated() {
      if index < 3 {
        let item: GWAudioItem = .fromNib()
        item.prepare(audio: audio)
        stackView.addArrangedSubview(item)
        
        item.snp.makeConstraints { maker in
          maker.height.equalTo(GWAudioItem.defaultHeight)
        }
      } else {
        break
      }
    }
  }
}

extension GWAudiosView {
  static var defaultHeight: CGFloat = 132
}
